package com.aabte.spring.annotation.config;

import com.aabte.spring.beanfactorypostprocessor.MyBeanFactoryPostProcessor;
import com.example.beans.Blue;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.AbstractApplicationContext;

/**
 *
 * {@link BeanFactoryPostProcessor#postProcessBeanFactory(ConfigurableListableBeanFactory)}Bean工厂后置处理器，
 *      在Bean工厂初始化后所有Bean未实例化之前被回调
 *
 * {@link BeanFactoryPostProcessor}原理：
 *  1、创建IOC容器对象
 *  2、执行{@link BeanFactoryPostProcessor}接口实现方法{@link AbstractApplicationContext#invokeBeanFactoryPostProcessors(ConfigurableListableBeanFactory)}
 *      1、获取所有{@link BeanFactoryPostProcessor}实现组件
 *      2、分组排序，依次回调{@link BeanFactoryPostProcessor#postProcessBeanFactory(ConfigurableListableBeanFactory)}方法
 *
 * {@link BeanDefinitionRegistryPostProcessor}原理：
 *  1、创建IOC容器对象
 *  2、执行{@link BeanFactoryPostProcessor}接口实现方法{@link AbstractApplicationContext#invokeBeanFactoryPostProcessors(ConfigurableListableBeanFactory)}
 *      1、获取所有{@link BeanDefinitionRegistryPostProcessor}实现
 *      2、分组排序
 *          1、依次回调{@link BeanDefinitionRegistryPostProcessor#postProcessBeanDefinitionRegistry(BeanDefinitionRegistry)}方法
 *          1、依次回调{@link BeanDefinitionRegistryPostProcessor#postProcessBeanFactory(ConfigurableListableBeanFactory)}方法
 *      3、之后回调{@link BeanFactoryPostProcessor}实现
 *
 * @author Daniel
 */
@Configuration
public class BeanFactoryPostProcessorConfig {

    @Bean
    public BeanFactoryPostProcessor myBeanFactoryPostProcessor (){
        return new MyBeanFactoryPostProcessor();
    }

    @Bean
    public Blue blue (){
        return new Blue();
    }

}
